<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
use Redirect, Input;
use App\Land;
use App\landowner;
use App\Contract;

class indexController extends Controller
{
    //
    public function __construct(){
    	$this->middleware('auth');
	}
    
    public function index()  
	{
		$landowner_count = DB::table('landowners')->count();
		$contract_count = DB::table('contracts')->count();
		$total_shandi1 = DB::table('lands')->where("catalog", CATALOG_SHANDI1)->sum("area");
		$total_shandi2 = DB::table('lands')->where("catalog", CATALOG_SHANDI2)->sum("area");
		$total_yuandi = DB::table('lands')->where("catalog", CATALOG_YUANDI)->sum("area");
		$total_money = DB::table('lands')->sum("amount");
		$contract_money = DB::table('contracts')->sum("amount");
		// $total_money = $total_shandi1*80+$total_shandi2*50+$total_yuandi*400;

	
	
		$land_count = $total_shandi1 + $total_shandi2 + $total_yuandi;
		$data = ["contract_count"=>$contract_count,
			"landowner_count"=>$landowner_count,
			"total_shandi1"=>$total_shandi1,
			"total_shandi2"=>$total_shandi2,
			"total_yuandi"=>$total_yuandi,
			"total_money"=>$total_money,
			"contract_money"=>$contract_money,
			"land_count"=>$land_count
			];

        return view('index' , $data);
	}
}
